package suzf.top.kotlinjava.common.utils

import java.text.DecimalFormat

/**
 *  byte转为mb，gb
 *========================
 * Created with IntelliJ IDEA
 * Author:Mr.Su
 * Date:2019/9/27
 * Time:13:47
 * ========================
 */
class Byte2Mb2GbUtils {

    companion object {
        fun getNetFileSizeDescription(size: Long): String {
            var strSie = ""
            val format = DecimalFormat("###.0")
            if (size >= 1024 * 1024 * 1024) {
                val i = size / (1024.0 * 1024.0 * 1024.0)
                strSie = "${format.format(i)}GB"
            }else if (size >= 1024 * 1024){
                val i = size / (1024.0 * 1024.0 * 1024.0)
                strSie = "${format.format(i)}MB"
            }else if (size >= 1024){
                val i = size / (1024.0)
                strSie = "${format.format(i)}MB"
            }else if (size < 1024) {
                if (size <= 0) {
                    strSie = "0B"
                } else {
                    strSie = "${size.toInt()}B"
                }
            }
            return strSie
        }
    }
}
